<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>接口调用-async/await用法</title>
	</head>
	<body>
		
		<script>
			/* 
			【1】async/await的基本用法
			-->async/await是ES7引入的新语法，可以更加方便的进行异步操作
			-->async关键字用于函数上(async函数的返回值是Promise实例对象)
			-->await关键字用于async函数当中(await可以得到异步的结果);可以跟一个Promise实例对象
			
			async function queryData(id){
				const ret = await axios.get("../test.php");
				return ret;
			}
			
			queryData.then(function(ret){
				console.log(ret);
			})
			============================================================
			【2】async/await处理多个异步请求
			
			async function queryData1(){
				var info = await axios.get("async1");
				var ret = await axios.get("async2?info="+info.data);
				return ret.data;
			}
					
			queryData1().then(data=>{
				console.log(data);
			})
			
			 */
			
			async function queryData(id){
				const ret = await axios.get("../test.php?id=id");
				return ret;
			}
			
			queryData.then(function(ret){
				console.log(ret);
			})
/* ================================================================ */		
			axios.get("../test.php").then(function(ret){
				console.log(ret.data);
			})
/* ======================================================== */
		    async function queryData1(){
				var info = await axios.get("async1");
				var ret = await axios.get("async2?info="+info.data);
				return ret.data;
			}
		
		    queryData1().then(data=>{
				console.log(data);
			})
		
		</script>
	</body>
</html>
